<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>提交订单</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <script src="js/rem.js"></script>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="css/base.css"/>
    <link rel="stylesheet" type="text/css" href="css/page.css"/>
    <link rel="stylesheet" type="text/css" href="css/all.css"/>
    <link rel="stylesheet" type="text/css" href="css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/loaders.min.css"/>
    <link rel="stylesheet" type="text/css" href="css/loading.css"/>
    <script type="text/javascript">
        var orderCoder = "";
        var price = "";
        var oid = "";
        var point = 0;
        var account=0;
        var changeStatusUrl = "../orders/changeStatus";
        var addPointUrl = "../points/addPointByOrderId";
        var userPointUrl = "../points/getByUid";
        var payByPointUrl = "../points/payByPoint";
        var payByCashUrl= "../cash/payByCash";


        $(window).load(function () {
            $(".loading").addClass("loader-chanage")
            $(".loading").fadeOut(300)
            getPathParams();
            getUserPoint();
            initPage();
        })

        function initPage() {
            $("#orderCode").html(orderCoder);
            $("#price").html(price);
            $("#pricePoint").html(price);
        }

        //获取当前用户积分,设置当前页面
        function getUserPoint() {
            //获取当前用户积分
            $.get(userPointUrl, function (result) {
                if (result.state == 1000) {
                    //设置显示当前可用积分
                    if( result.msg==true) {
                        point = result.data.num;
                    }else{
                        point=0;
                    }
                    $("#userPoint").html("剩余积分为："+point.toFixed());
                }
            });
        }

        //获取当前用户金额
        $.get("/cash/getCashByUid", function (result) {
            if (result.state == 1000) {
                if (result.msg == false) {
                    $("#cash").html(0);
                    account = 0;
                } else {
                    $("#cash").html("剩余钱包金额为："+result.data.account);
                    account = result.data.account;
                }
            }
        })

        //初始化获得订单号和订单金额
        function getPathParams() {
            // 获取地址栏中的status参数
            var path = window.location.href;
            var index = path.lastIndexOf("?");
            if (index != -1) {
                var param = path.substring(index + 1);
                var array = param.split(",");
                if (array.length > 0) {
                    orderCoder = array[0];
                    price = array[1];
                    oid = array[2]
                }
            }
        }



        //判断支付方式
        function choosePay() {

            var o = $("input[name='pay']:checked").val();

            var pointParam = {
                oid: oid
            }

            if (o == 0 || o == 1) {
                //支付成功，修改状态为收发货---status为2
                var params = {
                    status: 2,
                    oid: oid,
                    payStyle: o
                }



                $.post(changeStatusUrl, params, function (result) {
                    if (result.state == 1000) {
                        //微信支付成功，调用积分接口进行积分
                        $.post(addPointUrl, pointParam, function (result) {
                            if (result.state == 1000) {
                                if (o == 0) {
                                    alert("微信支付成功，即将跳转待收货界面")
                                }
                                if (o == 1) {
                                    alert("翼支付支付成功，即将跳转待收货界面")
                                }
                                //跳转为待收货界面
                                window.location.href = "re-order.html?" + 2;
                            }
                        })
                    } else {
                        alert(result.msg);
                    }
                })

            }
            if (o == 2) {
                //调用积分支付走积分接口
                //判断当前积分是否可以支付商品价格
                if (point >= price) {
                    //将订单id传过去,进行订单消费
                    $.post( payByPointUrl,pointParam, function (result) {
                        if (result.state == 1000) {
                            alert("积分支付成功，即将跳转待收货界面")
                            //跳转为收货界面
                            window.location.href = "re-order.html?" + 2;
                        }
                    });
                } else {
                    alert("积分不足，请选择微信支付或翼支付支付");
                }
            }
            if(o == 3){
                if (account >= price) {
                    //将订单id传过去,进行订单消费
                    $.post( payByCashUrl,pointParam, function (result) {
                        if (result.state == 1000) {
                            alert("钱包支付成功，即将跳转待收货界面")
                            //跳转为待发货界面
                            window.location.href = "re-order.html?" + 2;
                        }
                    });
                } else {
                    alert("积分不足，请选择微信支付或翼支付支付");
                }

            }
        }
    </script>
</head>
<!--loading页开始-->
<div class="loading">
    <div class="loader">
        <div class="loader-inner pacman">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>
<!--loading页结束-->
<body>
<header class="mui-bar mui-bar-nav report-header box-s" id="header">
    <a href="javascript:history.go(-1)"><i class="iconfont icon-fanhui fl"></i></a>
    <p>提交订单</p>
</header>
<div id="main" class="mui-clearfix contaniner sorder">
    <div class="warning clearfloat box-s">
        提示：请在24小时内完成在线支付，逾期将视为订单无效
    </div>
    <div class="odernum clearfloat">
        <ul>
            <li>您的订单号：<span id="orderCode"></span></li>
            <li>应付金额：<span id="price"></span>元</li>
            <li>或应付积分：<span id="pricePoint"></span>分</li>
        </ul>
    </div>
    <div class="pay-method clearfloat">
        <ul>
            <li>请选择支付方式</li>
        </ul>
    </div>
    <div class="addlist clearfloat">
        <div class="bottom clearfloat box-s">
            <section class="shopcar clearfloat">
                <div class="radio radiosss fr">
                    <label>
                        <input type="radio" name="pay" value="0">
                        <div class="option"></div>
                    </label>
                </div>
                <div class="sorder-list clearfloat fl">
                    <i class="iconfont icon-weixinzhifu fl"></i>
                    <div class="zuo fl">
                        <p class="tit">微信支付</p>
                        <p class="fu-tit">亿万用户的选择，更快更安全</p>
                    </div>
                </div>
            </section>
        </div>
        <div class="bottom clearfloat box-s">
            <section class="shopcar clearfloat">
                <div class="radio radiosss fr">
                    <label>
                        <input type="radio" name="pay" value="1">
                        <div class="option"></div>
                    </label>
                </div>
                <div class="sorder-list clearfloat fl">
                    <i class="iconfont icon-yinxingqia fl"></i>
                    <div class="zuo fl">
                        <p class="tit">翼支付</p>
                        <p class="fu-tit">客户端支持最便捷！可银行卡支付！</p>
                    </div>
                </div>
            </section>
        </div>
        <div class="bottom clearfloat box-s">
            <section class="shopcar clearfloat">
                <div class="radio fr">
                    <label>
                        <input type="radio" name="pay" value="2">
                        <div class="option"></div>
                    </label>
                </div>
                <div class="sorder-list clearfloat fl">
                    <i class="iconfont icon-yinxingqia fl"></i>
                    <div class="zuo fl">
                        <p class="tit">积分余额支付</p>
                        <p id="userPoint" class="fu-tit"></p>
                    </div>
                </div>
            </section>
        </div>
        <div class="bottom clearfloat box-s">
            <section class="shopcar clearfloat">
                <div class="radio fr">
                    <label>
                        <input type="radio" name="pay" value="3">
                        <div class="option"></div>
                    </label>
                </div>
                <div class="sorder-list clearfloat fl">
                    <i class="iconfont icon-yinxingqia fl"></i>
                    <div class="zuo fl">
                        <p class="tit">账户现金支付</p>
                        <p id="cash" class="fu-tit"></p>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <a href="#" onclick="choosePay()" class="address-add fl">
        确认支付
    </a>
</div>

</body>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script src="js/fastclick.js"></script>
<script src="js/mui.min.js"></script>
<script type="text/javascript" src="js/hmt.js"></script>
<script type="text/javascript">
    $(".shopcar-checkbox label").on('touchstart', function () {
        if ($(this).hasClass('shopcar-checkd')) {
            $(".shopcar-checkbox label").removeClass("shopcar-checkd")
        } else {
            $(".shopcar-checkbox label").addClass("shopcar-checkd")
        }
    })
</script>
</html>
